package com.wh.hotel.convert;

import cn.hutool.json.JSONUtil;
import com.wh.hotel.model.*;
import com.wh.hotel.po.PriceChangeVo;
import com.wh.hotel.po.StrategySuitRangePo;
import com.wh.hotel.po.ValidTimePo;
import com.wh.hotel.response.HotelBookRuleResponse;
import com.wh.hotel.response.HotelRoomDetailResponse;
import com.wh.hotel.vo.*;
import org.mapstruct.factory.Mappers;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Component;

/**
 * @author luweije
 */
@Component
public class HotelStructConvert {

    HotelStructMapper hotelStructMapper = Mappers.getMapper(HotelStructMapper.class);


    public HotelBaseInfo convertToHotelBaseInfo(HotelBaseInfoVo param) {
        return hotelStructMapper.convertToHotelBaseInfo(param);
    }

    public HotelBaseInfoVo convertToHotelBaseInfoVo(HotelBaseInfo hotelBaseInfo) {
        return hotelStructMapper.convertToHotelBaseInfoVo(hotelBaseInfo);
    }

    public HotelListWebVo convertToHotelListWebVo(HotelBaseInfo hotelBaseInfo) {
        return hotelStructMapper.convertToHotelListWebVo(hotelBaseInfo);
    }

    public HotelBookRuleResponse convertToHotelBookRuleResponse(HotelBookRule hotelBookRule) {
        HotelBookRuleResponse ruleResponse = hotelStructMapper.convertToHotelBookRuleResponse(hotelBookRule);
        HotelBookRuleVo hotelBookRuleVo = convertToHotelBookRuleVo(hotelBookRule);
        ruleResponse.setPayWayRuleVoList(hotelBookRuleVo.getPayWayRuleVoList());
        ruleResponse.setBreakfastNumList(hotelBookRuleVo.getBreakfastNumList());
        return ruleResponse;
    }

    public HotelBookRuleVo convertToHotelBookRuleVo(HotelBookRule hotelBookRule) {
        return JSONUtil.toBean(hotelBookRule.getRuleJson(), HotelBookRuleVo.class);
    }

    public HotelBookRule convertToHotelBookRule(HotelBookRuleVo hotelBookRuleVo) {
        HotelBookRule hotelBookRule = new HotelBookRule();
        hotelBookRule.setRuleName(hotelBookRuleVo.getRuleName());
        hotelBookRule.setRuleJson(JSONUtil.toJsonStr(hotelBookRuleVo));
        return hotelBookRule;
    }

    public HotelRoomType convertToHotelRoomType(HotelRoomTypeVo hotelRoomTypeVo) {
        return hotelStructMapper.convertToHotelRoomType(hotelRoomTypeVo);
    }

    public HotelRoomTypeRelation convertToHotelRoomTypeRelation(HotelRoomTypeVo hotelRoomTypeVo) {
        return hotelStructMapper.convertToHotelRoomTypeRelation(hotelRoomTypeVo);
    }

    public HotelRoomDetailResponse convertToHotelRoomDetailResponse(HotelRoomTypeRelation record) {
        return hotelStructMapper.convertToHotelRoomDetailResponse(record);
    }

    public void copyFieldToHotelRoomDetailResponse(HotelRoomDetailResponse response, HotelRoomType hotelRoomType) {
        BeanUtils.copyProperties(hotelRoomType, response);
    }

    public RoomGoodsDetailVo convertToRoomGoodsDetailVo(HotelRoomTypeGoods goods) {
        RoomGoodsDetailVo roomGoodsDetailVo = hotelStructMapper.convertToRoomGoodsDetailVo(goods);
        PayWayRuleVo payWayRuleVo = JSONUtil.toBean(goods.getCancelRule(), PayWayRuleVo.class);
        roomGoodsDetailVo.setFirstNightMinuteForStart(payWayRuleVo.getFirstNightMinuteForStart());
        roomGoodsDetailVo.setFreeCancelMinuteForStart(payWayRuleVo.getFreeCancelMinuteForStart());
        return roomGoodsDetailVo;
    }

    public HotelPricingStrategy convertToHotelPricingStrategy(HotelPriceStrategyVo hotelPriceStrategyVo) {
        HotelPricingStrategy hotelPricingStrategy = new HotelPricingStrategy();
        hotelPricingStrategy.setStrategyName(hotelPriceStrategyVo.getStrategyName());
        hotelPricingStrategy.setStrategyType(hotelPriceStrategyVo.getStrategyType());
        hotelPricingStrategy.setSuitRangeJson(JSONUtil.toJsonStr(hotelPriceStrategyVo.getSuitRangePo()));
        hotelPricingStrategy.setValidTimeJson(JSONUtil.toJsonStr(hotelPriceStrategyVo.getValidTimePo()));
        hotelPricingStrategy.setChangePriceJson(JSONUtil.toJsonStr(hotelPriceStrategyVo.getPriceChangeVo()));
        return hotelPricingStrategy;
    }

    public HotelPriceStrategyVo convertToHotelPriceStrategyVo(HotelPricingStrategy strategy) {
        HotelPriceStrategyVo hotelPriceStrategyVo = new HotelPriceStrategyVo();
        hotelPriceStrategyVo.setId(strategy.getId());
        hotelPriceStrategyVo.setCreateDt(strategy.getCreateDt());
        hotelPriceStrategyVo.setUpdateDt(strategy.getUpdateDt());
        hotelPriceStrategyVo.setStrategyName(strategy.getStrategyName());
        hotelPriceStrategyVo.setStrategyStatus(strategy.getStrategyStatus());
        hotelPriceStrategyVo.setStrategyType(strategy.getStrategyType());
        hotelPriceStrategyVo.setSuitRangePo(JSONUtil.toBean(strategy.getSuitRangeJson(), StrategySuitRangePo.class));
        hotelPriceStrategyVo.setValidTimePo(JSONUtil.toBean(strategy.getValidTimeJson(), ValidTimePo.class));
        hotelPriceStrategyVo.setPriceChangeVo(JSONUtil.toBean(strategy.getChangePriceJson(), PriceChangeVo.class));
        return hotelPriceStrategyVo;
    }
}
